package client.screen;

import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.TextField;

import client.MorcMIDlet;

public class ConfigurationScreen extends Screen {
	private TextField userName, password;
	private Command back, save;
	
	public ConfigurationScreen(MorcMIDlet midlet, String title) {
		super(midlet, title);
		
		this.userName = new TextField("Usuario", "", 32, TextField.PLAIN);
		this.password = new TextField("Senha", "", 32, TextField.PASSWORD);
		this.append(this.userName);
		this.append(this.password);
		
	}
	
	protected void addCommands() {
		this.back = new Command("Voltar", Command.BACK, 0);
		this.save = new Command("Salvar", Command.BACK, 0);
		
		this.addCommand(this.back);
		this.addCommand(this.save);
	}
	
	public void commandAction(Command c, Displayable d) {
		if (c == back) {
			this.midlet.setScreen(MorcMIDlet.SCREEN_MAIN);
		}
		else if (c == save) {
			this.midlet.configure(this.getUser(), this.getPass());
		}
	}
	
	public void setUser(String username) { 
		String usr = (username != null) ? username : "";
		this.userName.setString(usr);
		this.midlet.setUser(usr);
	}
	
	public void setPassword(String password) { 
		String pass = (password != null) ? password : "";
		this.password.setString(pass);
		this.midlet.setPassword(pass);
	}

	public String getUser() { return this.userName.getString(); }
	
	public String getPass() { return this.password.getString(); }
	
}
